package edu.pitt.cs.cs2510.project3.model;

/*
 * File: Request.java
 * Authors: Jesse Szwedko, Callen Shaw, Heather Friedberg
 * CS2510 Project 3
 */
public class Request {
	public Client client;
	public FrontEnd frontEnd;
	public Server server;
	
	public int issueTime;
	public int completionTime;
	
	public int requestCost;
	final public int id;
	public int fileId;
	public int size;
	public int currentBlockId; //the next block to be serviced
	public int lag;
	
	public static int nextId = 0;

	public Request(Client client, int issueTime, int fileId, int blocksPerFile) {
		super();
		this.client = client;
		this.issueTime = issueTime;
		this.fileId = fileId;
		this.currentBlockId = 0;
		this.requestCost = 0;
		this.size = blocksPerFile;
		this.lag = 0;
		this.id = Request.nextId++;
	}

	@Override
	public String toString() {
		return "Request [id=" + id + ", client=" + client + ", issueTime=" + issueTime
				+ ", completionTime=" + completionTime + ", requestCost="
				+ requestCost + ", fileId=" + fileId + ", size=" + size
				+ ", currentBlockId=" + currentBlockId + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Request other = (Request) obj;
		if (id != other.id)
			return false;
		return true;
	}	
}
